package com.cqupt.utils;


import com.cqupt.pojo.Databases;
import org.springframework.web.util.UriBuilder;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * 数据库连接类
 */
public class DatabaseUtils {
    /**
     *
     * @param ip
     * @param port
     * @param username
     * @param password
     * @return
     */
    public static int Link2Mysql(String ip,String port,String username,String password){
        final String URL = "jdbc:mysql://"+ip+":"+port+"/mysql?useSSL=true&useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai";
        final String USER = username;
        final String PWD = password;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        }catch (Exception  e){
            System.out.println("加载驱动异常"+e);
        }   try {
            Connection con = DriverManager.getConnection(URL,USER,PWD);
            con.close();
            return 1;
        }catch (SQLException e){
            e.getMessage();
            return 0;
        }
    }

    /**
     *
     * @param ip
     * @param port
     * @param username
     * @param password
     * @return
     */
    public static int Link2Oracle(String ip,String port,String username,String password){
        final String URL = "jdbc:oracle:thin:@"+ip+":"+port+"/orcl";
        final String USER = username;
        final String PWD = password;
        try {
            Class.forName("oracle.jdbc.OracleDriver");
        }catch (Exception  e){
            System.out.println("加载驱动异常"+e);
        }   try {
            Connection con = DriverManager.getConnection(URL,USER,PWD);
            con.close();
            return 1;
        }catch (SQLException e){
            e.getMessage();
            return 0;
        }
    }
}
